package com.kcsoft.welcome.controller;

import com.kcsoft.welcome.pojo.Member;
import com.kcsoft.welcome.pojo.PageBean;
import com.kcsoft.welcome.pojo.Result;
import com.kcsoft.welcome.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    MemberService memberService;

    @PostMapping("/add")
    public Result add(@Valid @RequestBody Member member) {
        memberService.add(member);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<PageBean<Member>> list(Integer pageNum, Integer pageSize) {

        PageBean<Member> pb = memberService.list(pageNum, pageSize);

        return Result.success(pb);
    }

    @PostMapping("/update")
    public Result update(@Valid @RequestBody Member member) {
        memberService.update(member);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result delete(Integer id) {
        memberService.delete(id);
        return Result.success();
    }

}
